package org.flower.isme.flower.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.flower.isme.common.preview.Preview;
import org.flower.isme.common.response.Page;
import org.flower.isme.common.response.R;
import org.flower.isme.flower.domain.entity.LightData;
import org.flower.isme.flower.domain.request.LightDataPageRequest;
import org.flower.isme.flower.service.LightDataService;
import org.flower.isme.netty.enums.Cmd;
import org.flower.isme.netty.handler.NettyServerHandler;
import org.springframework.web.bind.annotation.*;




@RestController
@RequestMapping("/light")
@RequiredArgsConstructor
@Tag(name = "光照")
public class LightDataController {

    private final LightDataService lightDataService;
    private final NettyServerHandler nettyServerHandler;

    /**
     * 上传光照数据
     *
     * @param lightData 光照数据
     * @return R
     */
    @PostMapping("/insert")
    @Preview
    @Operation(summary = "上传光照数据")
    public R<Void> updateLightData(@RequestBody LightData lightData) {
        lightDataService.save(lightData);
        nettyServerHandler.send(Cmd.CMD_005, "123456",lightData);
        return R.ok();
    }

    /**
     * 分页查询光照强度列表
     *
     * @param request 查询信息
     * @return R
     */
    @GetMapping("/list")
    @Preview
    @Operation(summary = "分页查询光照强度列表")
    public R<Page<LightData>> list(LightDataPageRequest request) {
        return R.ok(lightDataService.queryPage(request));
    }
}
